-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client/asset/dcr: refactor to support non-rpc wallets #1227
client/asset/dcr: refactor to support non-rpc wallets #1227
Conversation
@itswisdomagain and I chatted about this and I think it's a great idea. It opens the door to other Decred wallets like https://github.com/planetdecred/godcr, maybe something mobile long-term, maybe a built-in, etc. It takes an approach to a |
51d3927
to
faa1dce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
client/asset/dcr/rpcwallet.go
Outdated
var success bool | ||
defer func() { | ||
if !success { | ||
w.client.Shutdown() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just call Disconnect
over here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thought about it but wanted to maintain as much as possible what was in the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manual testing looks like everything is working.
92a02cc
to
4a920ae
Compare
The last commit 4a920ae adopts #1230's Here's an idea of how the new
The above works as long as it is called before Thoughts @chappjc @buck54321 @martonp? |
@itswisdomagain I don't understand your change. The point of the |
Agree with @martonp. Have a look at how the various It also seems to me that the caller of this Say dex were trying to use a new hypothetical DCR backend that is say a dcrlibwallet-based built-in... what is insufficient about Note that we've recently decided that |
OK I think I'm looking at this too rigidly, thinking that any possible But I think you're looking at an external package that implements So in this scenario, would it not be better to leave I'm now aware that @buck54321 has thoughts about doing something similar, except by registering a constructor for a particular wallet type, so I'll leave this to you guys to sort out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the overall goals of this work, but I do want to request some architectural changes.
With the changes in #1230, I don't think you need to provide a custom WalletInfo
, just a custom WalletDefinition
. How about a package-level method
type WalletConstructor func(cfg *asset.WalletConfig, logger dex.Logger, net dex.Network) (Wallet, error)
func RegisterCustomWallet(def *asset.WalletDefinition, constructor WalletConstructor)
It doesn't really have to be a driver method either. Just a package function.
I think that will negate the need for PrepareWallet
as well.
Works for me. I went with That said, EDIT: The idea is, some assets (dcr for now) might require some preparatory works of sort before they can be loaded. So while for most assets, it'd be sufficient to call |
For seeded/inbuilt wallets, Core just calls |
Just processing this, this could/should work, although I do not understand what purpose the I'm thinking of the following for the dcr asset:
Although, I wonder the implication of adding wallet types dynamically, e.g. but can probably deal with that after the fact. Also, would this mean each asset that want to support multiple ways of providing wallet functionality will have to do likewise? The only other alternative I see is adding new methods to the |
This is why I think these are two separate functions. One needs The answer to constructor vs. wallet interface provided to RegisterCustomWallet/UseCustomWallet is: whichever most effectively separates the caller from the concerns of the underlying custom wallet implementation. With a constructor as the arg, the caller does not need to make the actual wallet, only inform the asset package what constructor is to be used to make a wallet for a particular |
Missed that the constructor is to make a
Yeah, I agree. Whether that's why there should be separate methods on the Driver interface is where I'm less sure. Not to push it, but my reasoning is while both require different parameters and do different things, they share a similarity - getting the wallet ready to be loaded/used with |
4a920ae
to
883d934
Compare
Now using a package-level function as suggested by @buck54321. Not using Converted to draft for now, want to do a little cleanup before this will be ready for review again. |
883d934
to
e5815dd
Compare
client/asset/dcr/wallet.go
Outdated
// default rpcWallet implementation. External consumers can use this function | ||
// to provide alternative Wallet implementations, and must do so before an | ||
// ExchangeWallet instance is created. | ||
func RegisterCustomWallet(constructor WalletConstructor, info *asset.WalletInfo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, @itswisdomagain, thanks. When #1230 goes in, this can switch to WalletDefinition, as you've said, but overall this PR is looking pretty clean to me.
Introduce a Wallet interface for actual wallet functionality to be implemented by consumers as desired. rpcWallet type is added to implement the new Wallet interface using json-rpc commands over an rpc connection. This maintains the existing state of the dcr ExchangeWallet while allowing external consumers implement other types that do not require an rpc connection.
e5815dd
to
0312e7a
Compare
0312e7a
to
df9116e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple typos and questions, but looks and tests great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
2a4f3be
to
6a48850
Compare
6a48850
to
b01778a
Compare
Introduce a
Wallet
interface for actual wallet functionality tobe implemented by consumers as desired.
rpcWallet
type is added to implement the newWallet
interface usingjson-rpc commands over an rpc connection. This maintains the existing
state of the dcr ExchangeWallet while allowing external consumers
implement other types that do not require an rpc connection.